﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace PO_2011
{
    class Histogram : BitmapFastPixel
    {
        public static int[] CalcMonoHistogram(Bitmap image, int colorCount)
        {
            old_img = image;
            int[] channel = new int[colorCount];

            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    channel[getFastPixel(x, y)[0]]++;
                }
            }
            closeImage();

            return channel;
        }
        
        public static void CalcHistogram(Bitmap image, int colorCount, out int[] channelL, out int[] channelR, out int[] channelG, out int[] channelB)
        {
            old_img = image;
            channelL = new int[colorCount];
            channelR = new int[colorCount];
            channelG = new int[colorCount];
            channelB = new int[colorCount];

            int[] pColors;
            
            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    pColors = getFastPixel(x, y);
                    channelL[(int)Math.Ceiling((pColors[0] * 0.587) + (pColors[1] * 0.299) + (pColors[2] * 0.114))]++;
                    channelR[pColors[0]]++;
                    channelG[pColors[1]]++;
                    channelB[pColors[2]]++;
                }
            }
            closeImage();
        }

    }
}
